//
//  ViewController.m
//  03-UIResponder
//
//  Created by GivenBmli on 16/7/18.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    练习1
    TouchView *touchView = [[TouchView alloc]initWithFrame:CGRectMake(10, 10, 355, 200)];
    touchView.backgroundColor = [UIColor yellowColor];
    
    [self.view addSubview:touchView];
//    响应者链
//    检测顺序：硬件 - > AppDelegate - >UIApplication ->UIwindow ->UIViewController - >self.view -> TouchView
//     响应顺序：TouchView -> self.view ->UIViewContriler ->UIApplication ->AppDelegate ->null
//    如果所有的响应者都无法响应该事件，则这个事件会被舍弃
//    两种检测响应者的方法
//    1.Category 实现 touchBegin 的方法
//    2.nextResponder
//    例：
//    响应者不能出边界， 出边界则无法响应
//    判断当前的的店，这谁的范围内
    BOOL isInside = [touchView pointInside:CGPointMake(10, 210) withEvent:nil];
    NSLog(@"%@", isInside ? @"YES":@"NO");
    UIButton *buton =[UIButton buttonWithType:UIButtonTypeSystem];
    buton.frame = CGRectMake(10, 210, 200, 50);
    buton.backgroundColor = [UIColor greenColor];
    [touchView addSubview:buton];
    [buton addTarget:self action:@selector(buttonC:) forControlEvents:UIControlEventTouchUpInside];
//    2.button 的点击方法如何实现
//    button点击效果，通过UIResponder的方法
//    3.pointInside重写，实现失去的能力（return NO）

}

- (void)buttonC:(UIButton *)button{
    NSLog(@"%@", button);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@----------%s",NSStringFromClass([self class]), __FUNCTION__);
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
